********************************************************************************
* Household level analysis: Hours distribution
********************************************************************************

* log hours
gen log_hours_ann_hh = log(hours_ann_hh)

* compute variance log hours for the following sample restrictions
* consider singles if their annual hours are larger than 260 and lower than 4160 (80*52)
* consider couples (married or unmarried) if HH annual hours are larger than 520 and neither spouse works more than 4160 hours
* also checking that none of the (later) controls is missing 
sum log_hours_ann_hh if ((hh_type == 1 & hours_ann > 260 & hours_ann_max < 4160) | (hh_type == 2 & hours_ann_hh > 520 & hours_ann_max < 4160)) & hh_type != . & nkids != . & no1924 != . & no2560 != . & no6170 != . & no70 != . & age != . & college != .  & white != . & female != . [fw = asecwth], d

* Regress log hours under these restrictions on set of controls
reg log_hours_ann_hh i.hh_type i.nkids i.no1924 i.no2560 i.no6170 i.no70 i.age i.college i.white i.female if ((hh_type == 1 & hours_ann > 260 & hours_ann_max < 4160) | (hh_type == 2 & hours_ann_hh > 520 & hours_ann_max < 4160)) [fw = asecwth]
predict resid if ((hh_type == 1 & hours_ann > 260 & hours_ann_max < 4160) | (hh_type == 2 & hours_ann_hh > 520 & hours_ann_max < 4160)), residuals
* variance of residuals
sum resid [fw = asecwth], d

* residuals by quintiles
xtile resid_q = resid [fw = asecwth], nq(5)
bysort resid_q: sum resid [fw = asecwth]

********************************************************************************
* Household level analysis: Hours and wages
********************************************************************************

* Wage defined as household labor income divided by household hours
gen wage = inc_lab_hh/hours_ann_hh
gen log_wage = log(wage)

* Residualize wages (as hours)
reg log_wage i.hh_type i.nkids i.no1924 i.no2560 i.no6170 i.no70 i.age i.college i.white i.female if ((hh_type == 1 & hours_ann > 260 & hours_ann_max < 4160) | (hh_type == 2 & hours_ann_hh > 520 & hours_ann_max < 4160)) [fw = asecwth]
predict resid_wage if ((hh_type == 1 & hours_ann > 260 & hours_ann_max < 4160) | (hh_type == 2 & hours_ann_hh > 520 & hours_ann_max < 4160)), residuals

corr wage hours_ann_hh [fw = asecwth]
corr log_wage log_hours_ann_hh [fw = asecwth]
corr log_wage resid [fw = asecwth]
corr resid_wage resid [fw = asecwth]